package com.ssy.lingxi.message.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.message.api.vo.request.MessageIdRequest;
import com.ssy.lingxi.message.api.vo.request.MessageInviteMemberRequest;
import com.ssy.lingxi.message.api.vo.response.MessageResponse;
import com.ssy.lingxi.message.service.IMemberMessageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 系统能力-消息中心
 * @author yzc
 * @version 2.0.0
 * @date 2020/10/27
 */
@RestController
@RequestMapping("/message/message/member")
public class MemberMessageController extends BaseController {

    @Resource
    private IMemberMessageService messageService;

    /**
     * 系统能力-消息中心-消息分页列表
     * @param request 接口参数
     * @return 返回结果
     */
    @GetMapping("/page")
    Wrapper<PageData<MessageResponse>> pageMemberMessage(PageVO request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return messageService.pageMemberMessage(request, loginUser);
    }

    /**
     * 系统能力-消息中心-设置已读消息
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping("/read")
    Wrapper<Void> updateReadMemberMessage(@Validated @RequestBody MessageIdRequest request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return messageService.updateReadMemberMessage(request, loginUser);
    }

    /**
     * 系统能力-消息中心-设置全部已读消息
     * @return 返回结果
     */
    @PostMapping("/readAll")
    Wrapper<Void> updateAllReadMemberMessage() {
        UserLoginCacheDTO loginUser = getSysUser();
        return messageService.updateAllReadMemberMessage(loginUser);
    }

    /**
     * 商城能力 - 邀请成为我的会员
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping("/invite")
    Wrapper<Void> sendInviteMessage(@RequestBody @Valid MessageInviteMemberRequest request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return messageService.sendInviteMessage(request, loginUser);
    }

}
